package mvcdemo.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/dish")
public class RestController {
	/*
	 *   /dish/{dishId}
	 *   GET .....取ID为(dishID)的dish
	 *   PUT...... 更新ID为(dishID)的dish
	 *   DELETE... 删除ID为(dishID)的dish
	 *   
	 *   /dish
	 *   GET....取List<Dish>
	 *   POST.....增加一个dish
	 *   
	 *   /merchant/{merchantId}/dish{dishId}
	 */

	@RequestMapping(value="/{dishId}",method=RequestMethod.DELETE)  //{}是可变的值
	@ResponseBody
	public String deleteDish(@PathVariable int dishId){
		System.out.println("delete:"+dishId);
		return "dishSuccess";
	}
	
	
	@RequestMapping(value="/{dishId}",method=RequestMethod.POST)  //{}是可变的值
	@ResponseBody
	public String postDish(@PathVariable int dishId,String username,String address){
		System.out.println("post:"+dishId);
		System.out.println(username+"..."+address);
		return "dishSuccess";
	}
	
	@RequestMapping(value="/{dishId}",method=RequestMethod.POST)  //{}是可变的值
	public String addDish(@PathVariable int dishId,String username,String address){
		System.out.println("get:"+dishId);
		System.out.println(username+"..."+address);
		return "dishSuccess";
	}
	
	@RequestMapping(value="/{dishId}",method=RequestMethod.PUT)  //{}是可变的值
	public String updateDish(@PathVariable int dishId,@RequestParam Map<String, String> map){
		System.out.println("put:"+dishId);
		System.out.println(map.get("username")+"....."+map.get("address"));
		return "dishSuccess";
	}
}
